-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.py
35 lines (31 loc) · 909 Bytes
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Queue:
def __init__(self):
self.s1 = []
self.s2 = []
def enqueue(self, value):
self.s1.append(value)
def dequeue(self):
if not self.s2:
while self.s1:
self.s2.append(self.s1.pop())
if not self.s2:
print("Queue is empty")
return -1
return self.s2.pop()
if __name__ == "__main__":
q = Queue()
while True:
print("\n1. Enqueue\n2. Dequeue\n3. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
value = int(input("Enter value to enqueue: "))
q.enqueue(value)
elif choice == 2:
value = q.dequeue()
if value != -1:
print(f"Dequeued value: {value}")
elif choice == 3:
print("Exiting...")
break
else:
print("Invalid choice")